package com.hainatong.jcmvvmbase;


import android.content.Context;
import android.content.Intent;


import android.view.View;


import androidx.databinding.ViewDataBinding;
import com.google.android.material.snackbar.Snackbar;
import com.hainatong.jcmvvmbase.databinding.ActivityFirstBinding;
import com.hainatong.mvvmbase.base.BaseMvvmActivity;
import com.hainatong.mvvmbase.loadsir.core.LoadService;
import com.hainatong.mvvmbase.loadsir.core.LoadSir;
import com.hainatong.mvvmbase.loadsir.layoutcallback.*;
import com.hainatong.mvvmbase.utils.L;


public class FirstActivity extends BaseMvvmActivity<ActivityFirstBinding, TestViewModel>
{

    //private LoadService loadSer;

    public static void start(Context context)
    {
        Intent start = new Intent(context, FirstActivity.class);
        context.startActivity(start);
    }

    @Override
    protected int getLayoutId()
    {
        return R.layout.activity_first;
    }

    @Override
    protected void initView()
    {
        // 当全局 多状态页面 不满足 显示需求时 可以自定义 一个 loadser
        /*
        LoadSir loadSir = new LoadSir.Builder()
                .addCallback(new EmptyCallback())
                .addCallback(new ErrorCallback())
                .build();
        loadSer = loadSir.register(viewDataBinding.llRootView,v -> { onRetryBtnClick(); });
        loadSer.showCallback( EmptyCallback.class );
        */
        setLoadSir(this);

    }

    @Override
    protected void initData()
    {
        viewModel.username.set("点击");
        viewDataBinding.setViewModel(viewModel);
    }

    public void change(View view)
    {
        /*
         * viewModel.changeText().observe(this, aBoolean -> { if( aBoolean ) {
         * viewModel.username.set("改变"); } });
         */
        showLoading();
        //mLoadService.showCallback(AnimateCallback.class);
        viewModel.getInfoByNet("1").observe(this, result -> {

            //showContent();
            mLoadService.showCallback(TimeoutCallback.class);
            viewModel.username.set(result);

        });

    }

    @Override
    protected int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick()
    {
        Snackbar.make(viewDataBinding.getRoot(), "点击重试", Snackbar.LENGTH_LONG).show();
    }

}
